package login;

import java.io.IOException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import swimv2.session.LoginRemoteInterface;

public class RegistraAmministratoreServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7107498135642629716L;

	public RegistraAmministratoreServlet() {
		super();
	}

	public static Context getInitialContext() throws NamingException {

		Properties prop = new Properties();
		System.out.println("context");
		prop.setProperty("java.naming.factory.initial",
				"org.jnp.interfaces.NamingContextFactory");
		prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
		prop.setProperty("java.naming.provider.url", "127.0.0.1:1099");
		return new InitialContext(prop);

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		try {

			Context ctx = getInitialContext();
			LoginRemoteInterface LRI = (LoginRemoteInterface) ctx.lookup("LogicaLogin/remote");
			LRI.inserisciAmministratore(request.getParameter("nome"),
					request.getParameter("cognome"),
					request.getParameter("email"),
					request.getParameter("nomeutente"),
					request.getParameter("password"));
		} catch (Exception e) {
			System.out.println("ERRORE REGISTRAZIONE");
		}
	}

}
